home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 14 / Mac Magazin and MacEasy Magazine CD - Issue 14.iso / Wissenschaft & Technik / Tools Plus 2.6.1 Evaluation Kit / Tools Plus 2.6.1 / User Manual / 06-Buttons < prev    next >
INI File  |  1994-09-17  |  20KB  |  313 lines

  1. [Display using Monaco 9]
  2.  
  3.  
  4. 6  Buttons
  5. ``````````
  6.  
  7.   Tools Plus supports the use of buttons on any Tools Plus window.  Buttons are created on the current window by the NewButton procedure.  Each button is referenced by a unique button number, which can be from 1 to 255.  This number is specified when the button is created, and refers to the specific button until that button is deleted.  Note that the button number is related to its associated window.  This means that two different windows can each have a button numbered “1” without interfering with each other.  Whenever a button is clicked by the user, the PollSystem function reports the button number as well as its window number.
  8.  
  9.   When a button is no longer required, it is deleted by the DeleteButton procedure, which releases the memory used by that button.  This is done automatically if a window is closed.  Buttons can be renamed by using the ButtonTitle procedure.
  10.  
  11.  
  12.  
  13.  
  14.  
  15. Button Types
  16. ````````````
  17.   All three types of Macintosh buttons are supported by Tools Plus (push-button, radio button and check-box).  The push-button is clicked when the user wants to select it.  A push button is always used to “do something right now,” such as confirming or canceling a process.
  18.  
  19.   Check boxes and radio buttons are variations on a similar theme: they can be either selected or deselected by clicking on them.  The check box contains and “x” when checked, whereas the radio button contains a dot.  The difference between these two buttons is that radio buttons are logically grouped by your application such that only one button can be selected within the group.  When the user selects a radio button, your application de-selects the other buttons in the group.
  20.  
  21.  
  22.  
  23.  
  24.  
  25. Button States
  26. `````````````
  27.   All three button types can be either enabled or disabled by using the EnableButton procedure.  When a button is disabled, it becomes dim and cannot be selected by the user.  Check boxes and radio buttons can be either selected or de-selected by using the SelectButton procedure.
  28.  
  29.   When a window is inactive, all the associated buttons are automatically disabled and cannot be selected.  When the window is activated, the buttons are automatically returned to their normal state as set by your application.
  30.  
  31.  
  32.  
  33.  
  34.  
  35. Button Titles
  36. `````````````
  37.   A button’s title can be changed by the ButtonTitle procedure, however this should be done judicially since this can be confusing to the user.  A button’s title is centered in a push button, and left aligned in a check box or radio button.
  38.  
  39.  
  40.  
  41.  
  42.  
  43. Fonts
  44. `````
  45.   When a button is created, the window’s current font, size and style settings (as set by the TextFont, TextSize, and TextFace procedures) are remembered by the button.  The window’s settings can then be changed without affecting the button.  Unlike regular buttons, Tools Plus buttons can each have a different font.
  46.  
  47.  
  48.  
  49.  
  50.  
  51. Default Button
  52. ``````````````
  53.   One push button on each window can be designated to be the “default” button by the SetDefaultButton procedure.  This procedure draws an outline around the button.  If the Return or Enter key is pressed, Tools Plus responds as if the default button had been clicked.  The button’s default status can be cleared by the NoDefaultButton procedure.  A default button cannot be created on a tool bar or floating palette.
  54.  
  55.   When the user is working in an editing field, only the Enter key invokes the default push button.  This is done to avoid confusion between fields that can and cannot accept the Return key as a carriage return in the field.
  56.  
  57.  
  58.  
  59.  
  60.  
  61. Handling Buttons
  62. ````````````````
  63.   Your application specifies if check boxes or radio buttons are selected or not.  It also specifies if a button is enabled or disabled.  When a window in inactive, Tools Plus disables all buttons on that window.  When the window is activated again, all the buttons regain their correct status as specified by your application.
  64.  
  65.   The PollSystem function is used to constantly inquire about any events that have occurred, including clicking on buttons.  If a button is selected (i.e. the user presses the mouse button down and releases it within the button’s region), it is reported by PollSystem.  This also applies if the user presses the Enter or Return key when a window has a default button.  In the case of check boxes or radio buttons, your application must then select or de-select the button appropriately.
  66.  
  67.   When working with Radio Buttons, Tools Plus doesn’t know how these buttons are grouped, and therefore does not automatically turn off other radio buttons.  Your application must handle this.
  68.  
  69. Warning: If you have obtained a handle to a button, do not change any of
  70.          the fields in the button’s record.
  71.  
  72. ------------------------------------------------------------------------
  73.  
  74. NewButton
  75. `````````
  76. Create a new button.
  77.  
  78.    pascal void NewButton (short Button, short left, short top,
  79.                  short right, short bottom,
  80.                  Str255 Title, short procID,
  81.                  Boolean EnabledFlag, Boolean SelectedFlag);
  82.  
  83.    procedure NewButton(Button, left, top, right, bottom: INTEGER;
  84.                  Title: STRING; procID: INTEGER;
  85.                  EnabledFlag, SelectedFlag: BOOLEAN);
  86.  
  87.   Button specifies the button number (from 1 to 255) that is created in the current window.  Once a button is created, it is referenced by this button number.  If a button has been previously created in the current window using the same number, it is replaced with a new button as specified by the parameters in the NewButton procedure.  If the current window doesn’t belong to your application, or if no windows are open, NewButton does nothing.
  88.  
  89.   Left, top, right, and bottom define a rectangle in local co-ordinates that determines the button’s size and location in the window.  These parameters can be seen as two corners; the upper left-hand corner (left,top) and the bottom right-hand corner (right,bottom).  See the chart below regarding the minimum height for buttons.  These measurements are based on using the system font (Chicago) for the button’s text.
  90.  
  91.                               Minimum Height            Standard
  92.                       With Descenders  No Descenders     Height
  93.    Push Buttons               18           13              20
  94.    Radio/Check Box Buttons    14           12              16
  95.  
  96.  
  97.   The Title parameter is the button’s title.  Each button should have a unique title.  Button titles can have multiple lines, each line being separated by the ASCII character code $0D (carriage return).  It is your responsibility to ensure that the rectangle defining the button’s co-ordinates is sufficient to contain the button’s title.
  98.  
  99.   ProcID is the button definition ID, which specifies the button’s appearance and behavior.  The following are the three standard button definitions.
  100.       pushButProc  = push-button
  101.       checkBoxProc = check box
  102.       RadioButProc = radio button
  103.  
  104.   The EnabledFlag indicates if the newly created button is enabled or not.  All three button types can be either enabled or disabled.  When a button is disabled, it becomes dim and cannot be selected by the user.  All buttons automatically become disabled when the window containing them is inactive.  When the window is activated, the buttons assume their state as set by the NewButton procedure and subsequent calls to the EnableButton procedure.  The two constants that can be used for this flag are enabled and disabled.
  105.  
  106.   The SelectedFlag indicates if the newly created button is selected or not.  Only check boxes and radio buttons can be selected (this setting has no effect on push buttons).  The two constants that can be used for this flag are selected and notSelected.
  107.  
  108.  
  109.  
  110. Fonts
  111. `````
  112.   By default, all buttons are drawn using the system font (Chicago, 12 point).  Buttons can also be drawn using the window’s current font, size and style settings (as set by the TextFont, TextSize, and TextFace procedures) by adding the constant useWFont to the procID (i.e. pushButProc + useWFont).  When a button is created, the window’s current font, size and style settings are remembered by the button.  The window’s settings can then be changed without affecting any buttons.  The button’s font, size, and style cannot be changed without recreating the button.
  113.  
  114.  
  115.  
  116. Default Button
  117. ``````````````
  118.   When specifying the ProcID, you can optionally make one of the push buttons the “default” for the window.  The default button is automatically selected if the user presses the “Return” key or “Enter” key.  To make a button the default, specify a ProcID of pushButProc + DefaultButton, or simply use DefaultButton as a procID.  A black outline is drawn around the default button.  The outline is automatically grayed out whenever the default button is disabled.  A default button cannot be created on a tool bar or floating palette.
  119.  
  120.   If a default button already exists in the current window and you specify another button, the original one loses its “default” status.  Note that only 1 button can be the default in each window, and that it must be a push button.
  121.  
  122. Note: Tools Plus makes no attempt to control the placement of buttons or
  123.       to protect them once they have been created.  It is the
  124.       programmer’s responsibility to ensure that buttons are of
  125.       sufficient size to contain their title, and that their placement
  126.       within the window is reasonable and does not conflict with other
  127.       objects.  Furthermore, you should not allow the application’s text
  128.       and drawing processes to interfere with buttons, or with the
  129.       “default button” frame.  Windows with a “size box” should not
  130.       allow buttons to be obscured or hidden by making the window too
  131.       small.
  132.  
  133. Also see:  NewButtonRect.
  134.  
  135.   CONST                   {Button definition IDs                   }
  136.     pushButProc  =0;      {Push button                             }
  137.     checkBoxProc =1;      {check box                               }
  138.     RadioButProc =2;      {radio button                            }
  139.     DefaultButton=4;      {default push button (1 only per window) }
  140.     useWFont     =8;      {added to ProcID to use the window’s font}
  141.                           {Button state…                           }
  142.     enabled      =true;   {enable button                           }
  143.     disabled     =false;  {disable button                          }
  144.     selected     =true;   {select (check) button                   }
  145.     notSelected  =false;  {deselect (un-check) button              }
  146.  
  147. ------------------------------------------------------------------------
  148.  
  149. NewButtonRect
  150. `````````````
  151. Create a new button.
  152.  
  153.    pascal void NewButtonRect (short Button, Rect *Bounds, Str255 Title,
  154.                  short procID, Boolean EnabledFlag,
  155.                  Boolean SelectedFlag);
  156.  
  157.    procedure NewButtonRect(Button: INTEGER; Bounds: RECT; Title: STRING;
  158.                  procID: INTEGER; EnabledFlag, SelectedFlag: BOOLEAN);
  159.  
  160.   NewButtonRect is identical to the NewButton procedure, except that it accepts the Bounds rectangle in place of the individual left, top, right and bottom co-ordinates.
  161.  
  162. ------------------------------------------------------------------------
  163.  
  164. DeleteButton
  165. ````````````
  166. Delete a button.
  167.  
  168.    pascal void DeleteButton (short Button);
  169.  
  170.    procedure DeleteButton(Button: INTEGER);
  171.  
  172.   Button specifies the button number (from 1 to 255) that is deleted from the current window.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, DeleteButton does nothing.
  173.  
  174. ------------------------------------------------------------------------
  175.  
  176. EnableButton
  177. ````````````
  178. Enable or disable a button.
  179.  
  180.    pascal void EnableButton (short Button, Boolean EnabledFlag);
  181.  
  182.    procedure EnableButton(Button: INTEGER; EnabledFlag: BOOLEAN);
  183.  
  184.   Button specifies the button number (from 1 to 255) that is affected in the current window.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, EnableButton does nothing.
  185.  
  186.   The EnabledFlag indicates if the button is enabled or not.  All three button types can be either enabled or disabled.  When a button is disabled, it becomes dim and cannot be selected by the user.  All buttons automatically become disabled when the window containing them is inactive.  When the window is activated, the buttons assume their state as set by the NewButton procedure, and subsequent calls to the EnableButton procedure.  The two constants that can be used for this flag are enabled and disabled.
  187.  
  188.   CONST                   {Button state                           }
  189.     enabled     =true;    {button is enabled                      }
  190.     disabled    =false;   {button is disabled                     }
  191.  
  192.   See the NewButton procedure for additional information pertaining to the button’s enabling, disabling, and selection (i.e. checked or not).
  193.  
  194. ------------------------------------------------------------------------
  195.  
  196. SelectButton
  197. ````````````
  198. Select or deselect (check or un-check) a button.
  199.  
  200.    pascal void SelectButton (short Button, Boolean SelectedFlag);
  201.  
  202.    procedure SelectButton(Button: INTEGER; SelectedFlag: BOOLEAN);
  203.  
  204.   Button specifies the button number (from 1 to 255) that is affected in the current window.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, SelectButton does nothing.
  205.  
  206.   The SelectedFlag indicates if the button is selected (checked) or not.  Only check boxes and radio buttons can be selected.  This setting has no effect on push buttons.  The two constants that can be used for this flag are selected and notSelected.
  207.  
  208.   CONST                   {Button state                           }
  209.     selected    =true;    {button is selected (checked)           }
  210.     notSelected =false;   {button is not selected (not checked)   }
  211.  
  212.   See the NewButton procedure for additional information pertaining to the button’s enabling, disabling, and selection (i.e. checked or not).
  213.  
  214. ------------------------------------------------------------------------
  215.  
  216. ButtonIsEnabled
  217. ```````````````
  218. Determine if a button is enabled or disabled.
  219.  
  220.    pascal Boolean ButtonIsEnabled (short Button);
  221.  
  222.    function ButtonIsEnabled(Button: INTEGER): BOOLEAN;
  223.  
  224.   Button specifies the button number (from 1 to 255) which is queried in the current window.
  225.  
  226.   The function’s value returns true if the button is enabled, and false if the button is disabled.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, ButtonIsEnabled returns false.
  227.  
  228.   CONST                   {Button state                           }
  229.     enabled     =true;    {button is enabled                      }
  230.     disabled    =false;   {button is disabled                     }
  231.  
  232.   See the NewButton procedure for additional information pertaining to the button’s enabling, disabling, and selection (i.e. checked or not).
  233.  
  234. Note: ButtonIsEnabled returns the button’s state as though the button’s
  235.       window is active.  This is the case even when the window is
  236.       deactivated and all the buttons appear disabled.
  237.  
  238. ------------------------------------------------------------------------
  239.  
  240. ButtonIsSelected
  241. ````````````````
  242. Determine if a button is selected (i.e. checked).
  243.  
  244.    pascal Boolean ButtonIsSelected (short Button);
  245.  
  246.    function ButtonIsSelected(Button: INTEGER): BOOLEAN;
  247.  
  248.   Button specifies the button number (from 1 to 255) that is queried in the current window.
  249.  
  250.   The function’s value returns true if the button is selected (checked), and false if the button is not selected.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, ButtonIsSelected returns false.
  251.  
  252.   CONST                   {Button state                           }
  253.     selected    =true;    {button is selected (checked)           }
  254.     notSelected =false;   {button is not selected (not checked)   }
  255.  
  256.   See the NewButton procedure for additional information pertaining to the button’s enabling, disabling, and selection (i.e. checked or not).
  257.  
  258. ------------------------------------------------------------------------
  259.  
  260. ButtonTitle
  261. ```````````
  262. Change a button’s title.
  263.  
  264.    pascal void ButtonTitle (short Button, Str255 Title);
  265.  
  266.    procedure ButtonTitle(Button: INTEGER; Title: string);
  267.  
  268.   Button specifies the button number (from 1 to 255) that is affected in the current window.  If the current window doesn’t belong to your application, or if no windows are open, or if the button does not exist in the current window, ButtonTitle does nothing.
  269.  
  270.   The Title parameter is the button’s title.  Each button should have a unique title.  Button titles can have multiple lines, each line being separated by the ASCII character code $0D (carriage return).  Note that a button’s size does not change automatically to accommodate larger or smaller titles.
  271.  
  272. ------------------------------------------------------------------------
  273.  
  274. FlashButton
  275. ```````````
  276. Flash a button as though it was clicked by the user.
  277.  
  278.    pascal void FlashButton (short Button);
  279.  
  280.    procedure FlashButton(Button: INTEGER);
  281.  
  282.   Button specifies the button number (from 1 to 255) that is affected in the active window.  If the active window doesn’t belong to your application, or if no windows are open, FlashButton does nothing.
  283.  
  284.   FlashButton can be used in some specific instances.  Advanced programmers may decide to display a modal window when the Macintosh is busy with a lengthy process.  If a button (such as “Cancel”) on this window is equivalent to typing Command-., the button should be flashed when a Command-. is reported by PollSystem.  This makes the user feel that the key triggered the button.  Another example is double-clicking in a list box; this action can be interpreted as “select line and OK” in which case the OK button should be flashed.  This also occurs if your application interprets double-clicking a radio button as “select button and OK.”
  285.  
  286. ------------------------------------------------------------------------
  287.  
  288. SetDefaultButton
  289. ````````````````
  290. Set a button to be a window’s “default” button.
  291.  
  292.    pascal void SetDefaultButton (short Button);
  293.  
  294.    procedure SetDefaultButton(Button: INTEGER);
  295.  
  296.   Button specifies the button number (from 1 to 255) that will become the new default button in the current window.  If the current window doesn’t belong to your application, or if no windows are open, SetDefaultButton does nothing.  Also, if Button specifies a button that is not a push button, or a button that does not exist, SetDefaultButton does nothing.  A default button cannot be set on a tool bar or floating palette.
  297.  
  298.   The default button is automatically selected if the user presses the “Return” key or “Enter” key.  A black outline is automatically drawn around the default button when the window is active.  If another default button already exists in the current window, it loses its “default” status.  Note that only 1 button can be the default in each window.
  299.  
  300. ------------------------------------------------------------------------
  301.  
  302. NoDefaultButton
  303. ```````````````
  304. Remove “default button” status for a window.
  305.  
  306.    pascal void NoDefaultButton(void);
  307.  
  308.    procedure NoDefaultButton;
  309.  
  310.   This procedure removes the “default button” status from the current window (i.e. a specific button will not be automatically selected when the user presses the “Return” key or “Enter” key).  The black outline that is automatically drawn around the default button is removed.  Buttons themselves, however, are not altered.  If the current window doesn’t belong to your application, or if no windows are open, NoDefaultButton does nothing.
  311.  
  312. ------------------------------------------------------------------------
  313.